package com.lechi.web.common.alarm;

import org.springframework.stereotype.Component;

/**
 * 告警规则容器
 */
@Component
public class AlarmRuleFactory {
//
//    private final static Map<String, AlarmRuleStrategy> alarmRuleMap = new HashMap<>();
//
//    public static void register(String key, AlarmRuleStrategy alarmRuleStrategy) {
//        alarmRuleMap.put(key, alarmRuleStrategy);
//    }

    public static AlarmRuleStrategy getAlarmRuleStrategy(String key) {
        AlarmRuleStrategy alarmRuleStrategy = switch (key) {
            case "aboveX":
                yield new AboveX();
            case "belowY":
                yield new BelowY();
            case "aboveXOrBelowY":
                yield new AboveXOrBelowY();
            case "aboveXOrBelowYAndOverTime":
                yield new AboveXOrBelowYAndOverTime();
            case "betweenXAndY":
                yield new BetweenXAndY();
            case "betweenXAndYAndOverTime":
                yield new BetweenXAndYOverTime();
            case "overMDurationTimeAboveX":
                yield new OverMDurationTimeAboveX();
            case "overMDurationTimeBelowY":
                yield new OverMDurationTimeBelowY();
            case "switchOn":
                yield new SwitchOnOrOff(1);
            case "switchOff":
                yield new SwitchOnOrOff(0);
            case "equalsAboveX":
                yield new EqualsAboveX();
            case "notEqualsAboveX":
                yield new NotEqualsAboveX();
            default:
                throw new IllegalArgumentException("未知的告警规则类型: " + key);
        };
        return alarmRuleStrategy;
    }

//    @PostConstruct
//    public void init() {
//        register("aboveX", new AboveX());
//        register("belowY", new BelowY());
//        register("aboveXOrBelowY", new AboveXOrBelowY());
//        register("aboveXOrBelowYAndOverTime", new AboveXOrBelowYAndOverTime());
//        register("betweenXAndY", new BetweenXAndY());
//        register("betweenXAndYAndOverTime", new BetweenXAndYOverTime());
//        register("overMDurationTimeAboveX", new OverMDurationTimeAboveX());
//        register("overMDurationTimeBelowY", new OverMDurationTimeBelowY());
//        register("switchOn", new SwitchOnOrOff(1));
//        register("switchOff", new SwitchOnOrOff(0));
//        register("equalsAboveX", new EqualsAboveX());
//        register("notEqualsAboveX", new NotEqualsAboveX());
//    }

}
